/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.sober.criteria.expression;

import com.jspx.sober.TableModels;
import com.jspx.sober.criteria.projection.Criterion;
import com.jspx.sober.util.JdbcUtil;

/**
 * Created by IntelliJ IDEA.
 * User:chenYuan (mail:39793751@qq.com)
 * Date: 2007-1-8
 * Time: 23:27:49
 */
public class SimpleExpression implements Criterion
{

    private String propertyName;
    private Object value;
    private String op;

    public SimpleExpression(String propertyName, Object value, String op)
    {
        this.propertyName = propertyName;
        this.value = value;
        this.op = op;
    }

    public SimpleExpression ignoreCase()
    {
        return this;
    }

    public String toSqlString(TableModels soberTable,String databaseName)
    {
        StringBuilder sb = new StringBuilder();
        sb.append(propertyName).append(op).append("? ");
        return sb.toString();
    }

    public Object[] getParameter(TableModels soberTable)
    {
        return JdbcUtil.appendArray(null, value);
    }

    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        sb.append(propertyName).append(getOp()).append(value);
        return sb.toString();
    }

    public String[] getFields()
    {
        return new String[]{propertyName};
    }

    protected final String getOp()
    {
        return op;
    }

    public String termString()
    {
        return toString();
    }
}